/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Clases;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author p4nsho
 */
public class Bus {
    String PATENTE_BUS,RUT_CHOFER,MARCA_BUS,MODELO_BUS,NOMBRE_CHOFER,APELLIDO_CHOFER,SEXO_CHOFER;
    int YEAR_BUS,CAPACIDAD_BUS,MOVIL_CHOFER;

    public String getNOMBRE_CHOFER() {
        return NOMBRE_CHOFER;
    }

    public void setNOMBRE_CHOFER(String NOMBRE_CHOFER) {
        this.NOMBRE_CHOFER = NOMBRE_CHOFER;
    }

    public String getAPELLIDO_CHOFER() {
        return APELLIDO_CHOFER;
    }

    public void setAPELLIDO_CHOFER(String APELLIDO_CHOFER) {
        this.APELLIDO_CHOFER = APELLIDO_CHOFER;
    }

    public String getSEXO_CHOFER() {
        return SEXO_CHOFER;
    }

    public void setSEXO_CHOFER(String SEXO_CHOFER) {
        this.SEXO_CHOFER = SEXO_CHOFER;
    }

    public int getMOVIL_CHOFER() {
        return MOVIL_CHOFER;
    }

    public void setMOVIL_CHOFER(int MOVIL_CHOFER) {
        this.MOVIL_CHOFER = MOVIL_CHOFER;
    }
    conectate con;

    public Bus() {
        con=new conectate();
    }

           public Bus buscar(String patente){
        Bus u=null;
        Connection cn=null;
        PreparedStatement pr=null;
        ResultSet rs=null;
        try{
            conectate c=new conectate();
            cn=c.getConnection();
            String sql="SELECT B.PATENTE_BUS,B.RUT_CHOFER,B.MARCA_BUS,B.MODELO_BUS,C.NOMBRE_CHOFER,C.APELLIDO_CHOFER,C.SEXO_CHOFER,C.MOVIL_CHOFER"
                    + " FROM BUS AS B, CHOFER AS C "
                    + "WHERE B.RUT_CHOFER=C.RUT_CHOFER AND PATENTE_BUS=? ";
            pr=cn.prepareStatement(sql);
            pr.setString(1, patente);
            rs=pr.executeQuery();
            while(rs.next()){
                u=new Bus();
                u.setPATENTE_BUS(rs.getString("PATENTE_BUS"));
                u.setRUT_CHOFER(rs.getString("RUT_CHOFER"));
                u.setMARCA_BUS(rs.getString("MARCA_BUS"));
                u.setMODELO_BUS(rs.getString("MODELO_BUS"));
                u.setNOMBRE_CHOFER(rs.getString("NOMBRE_CHOFER"));
                u.setAPELLIDO_CHOFER(rs.getString("APELLIDO_CHOFER"));
                u.setSEXO_CHOFER(rs.getString("SEXO_CHOFER"));
                u.setMOVIL_CHOFER(rs.getInt("MOVIL_CHOFER"));
                break;
            }
        }catch(SQLException e){
            JOptionPane.showMessageDialog(null, e);
            u=null;
        }finally{
            try{
                rs.close();
                pr.close();
                rs.close();
            }catch(SQLException e){
                JOptionPane.showMessageDialog(null, e);
            }
        }
        return u;
    
    
    
}

    public String getPATENTE_BUS() {
        return PATENTE_BUS;
    }

    public void setPATENTE_BUS(String PATENTE_BUS) {
        this.PATENTE_BUS = PATENTE_BUS;
    }

    public String getRUT_CHOFER() {
        return RUT_CHOFER;
    }

    public void setRUT_CHOFER(String RUT_CHOFER) {
        this.RUT_CHOFER = RUT_CHOFER;
    }

    public String getMARCA_BUS() {
        return MARCA_BUS;
    }

    public void setMARCA_BUS(String MARCA_BUS) {
        this.MARCA_BUS = MARCA_BUS;
    }

    public String getMODELO_BUS() {
        return MODELO_BUS;
    }

    public void setMODELO_BUS(String MODELO_BUS) {
        this.MODELO_BUS = MODELO_BUS;
    }

    public int getYEAR_BUS() {
        return YEAR_BUS;
    }

    public void setYEAR_BUS(int YEAR_BUS) {
        this.YEAR_BUS = YEAR_BUS;
    }

    public int getCAPACIDAD_BUS() {
        return CAPACIDAD_BUS;
    }

    public void setCAPACIDAD_BUS(int CAPACIDAD_BUS) {
        this.CAPACIDAD_BUS = CAPACIDAD_BUS;
    }

    public conectate getCon() {
        return con;
    }

    public void setCon(conectate con) {
        this.con = con;
    }
    
}
